<template>
    <div class="content">
      <el-select placeholder="全部" v-model="area" style="width: 200px; margin-bottom: 20px;">
        <el-option v-for="item in areaOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
      </el-select>
  
      <div v-if="selectedImageUrl">
        <img :src="selectedImageUrl" alt="Radar Image" style="width: 100%; max-width: 750px; margin-top: 20px;" />
      </div>
    </div>
  </template>
  
  <script>
  import Request from '@/api/weather/request';
  import { Message } from 'element-ui';
  
  export default {
    data() {
      return {
        area: '雅安', 
        areaOptions: [
          { label: '全部', value: '雅安' },
          { label: '宝兴', value: '宝兴' },
          { label: '汉源', value: '汉源' },
          { label: '九龙', value: '九龙' },
          { label: '芦山', value: '芦山' },
          { label: '冕宁', value: '冕宁' },
          { label: '名山', value: '名山' },
          { label: '石棉', value: '石棉' },
          { label: '天全', value: '天全' },
          { label: '荥经', value: '荥经' },
          { label: '雨城', value: '雨城' }
        ],
        selectedImageUrl: null,
        list: [],
        currentPage: 1,
        pageSize: 13,
        total: 0,
      };
    },
    methods: {
      async fetchData(page = 1) {
        try {
          const response = await Request.get(`/weatherfacts/RainLivePic`, {
            params: {
              county: this.area, 
            }
          });
  
          if (response.status === 200) {
            this.list = response.data.data;
            this.selectedImageUrl = response.data.data.minioUrl; 
          } else {
            console.log('请求出错');
          }
        } catch (error) {
          console.error('请求失败', error);
        }
      },
  
      handleAreaChange(selectedArea) {
        this.area = selectedArea;
        this.fetchData();
      },
  
      handlePageChange(page) {
        this.currentPage = page;
        this.fetchData(page);
      },
  
      headerCellStyle() {
        return {
          background: "#0c2340",
          color: "#fff"
        };
      },
  
      cellStyle() {
        return {
          background: "#05152e",
          color: "#fff"
        };
      },
  
      rowStyle() {
        return {
          height: "30px"
        };
      }
    },
  
    watch: {
      area() {
        this.currentPage = 1;
        this.fetchData();
      }
    },
  
    mounted() {
      this.fetchData();
    }
  };
  </script>
  
  <style scoped>
  .content {
    width: 100%;
    text-align: center;
  }
  </style>
  